//
//  YXUser.swift
//  yanXiangWeiBo
//
//  Created by 颜祥 on 15/12/23.
//  Copyright © 2015年 yanxiang. All rights reserved.
//

import UIKit

class YXUser: NSObject
{
    // MARK: - 定义属性
    
    // 用户id
    var id: Int = 0
    
    // 用户昵称
    var screen_name: String?
    
    // 用户头像地址
    var profile_image_url: String?
    
    // 用户认证类型 -1: 没有认证 0: 认证 企业认证:2,3,5 达人:220
    var verified_type: Int = -1
    {
        didSet
        {
            switch verified_type
            {
            case 0: //没有认证
                verifiedImage = UIImage(named: "avatar_grassroot")
            case 2,3,5: // 企业认证
                verifiedImage = UIImage(named: "avatar_enterprise_vip")
            case 220: // 达人认证
                verifiedImage = UIImage(named: "avatar_vip")
            default:
                verifiedImage = nil
            }
        }
    }
    
    // 会员等级
    var mbrank: Int = 0
    {
        didSet
        {
            if mbrank > 0 && mbrank < 6
            {
                mbrankImage = UIImage(named: "common_icon_membership_level\(mbrank)")
            }
            else
            {
                // 清空图片，防止cell重用
                mbrankImage = nil
            }
        }
    }
    
    // 直接提供会员等级图片
    var mbrankImage: UIImage?
    
    // 直接提供会员认证图片
    var verifiedImage: UIImage?
    
    
    
    
   
    // MARK: - 字典转模型
    init(dict: [String: AnyObject]) {
        
        super.init()
        
        // KVC
        setValuesForKeysWithDictionary(dict)
    }
    
    // 字典的key在模型中没有找到对应的属性
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    // MARK: - 打印对象
    override var description: String
    {
        let prop = ["id","screen_name","profile_image_url","verified_type","mbrank"];
        let dict = dictionaryWithValuesForKeys(prop)
        
        
        return "\n\t\t用户模型: \(dict)"
    }
    
    
}
